package main

import (
	"gitee.com/go-wena/cli"
	"gitee.com/go-wena/wena"
	"os"
	"path/filepath"
)

func init() {
	cli.New(
		cli.Use("init [-f | -force] <module-path>"),
		cli.Comment("初始化项目"),
		cli.Flags(func(fs *cli.FlagSet) {
			fs.BoolP("force", "f", false, "是否覆盖")
			fs.BoolP("verbose", "v", false, "显示执行的命令行")
		}),
		cli.Run(func(c *cli.Command, args []string) {
			if len(args) != 1 {
				_ = c.Help()
				return
			}
			force, _ := c.Flags().GetBool("force")
			verbose, _ := c.Flags().GetBool("verbose")
			modulePath := ""
			if len(args) > 0 {
				modulePath = args[0]
			} else {
				pwd, err := os.Getwd()
				cli.CheckErr(err)
				if pwd != "" {
					modulePath = filepath.Base(pwd)
				}
			}

			err := wena.ProjectInit(c.Context(), modulePath, force, verbose)
			cli.CheckErr(err)
		}),
	).AddTo(root)
}
